package xyz.ddlnt.management.general.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.model.vo.FileUploadVO;
import xyz.ddlnt.servicegeneralclient.client.MinioFeignClient;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/1 21:54
 */
@Slf4j
@Tag(name = "文件上传接口")
@RestController
@RequestMapping("/minio")
public class MinioController {

    @Resource
    private MinioFeignClient minioFeignClient;

    @Operation(summary = "文件上传")
    @PostMapping("/upload")
    public Result<FileUploadVO> upload(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
        try {
            // 确保请求体被完全读取
            request.getInputStream().skip(request.getContentLength());
        }catch (Exception e) {
            log.error("web-mg：请求体读取失败：{}", e.getMessage());
        }
        Result<FileUploadVO>  uploadResult = minioFeignClient.upload(file);
        log.info("上传文件成功：{}", uploadResult.getData());
        return uploadResult;
    }
}